{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "14754e13",
   "metadata": {},
   "source": [
    "# 人脸检测api"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "eca0391d",
   "metadata": {},
   "source": [
    "## face++ 里有api_key api_secret与及api各个测试接口的url  “face_detect”"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "34cfe4e6",
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "5924b0df",
   "metadata": {},
   "outputs": [],
   "source": [
    "#01\n",
    "#输入我们需要api网站注册的api-key\n",
    "\n",
    "\n",
    "API_Key = \"E5SoP-JF_vrCoNK1gsKRt-10o4kaTm5r\"\n",
    "API_secret = \"TSlEaPXdmJV5w7xkKzuBW_IMRRoPKOXv\"\n",
    "\n",
    "#准备api测试接口的url\n",
    "face_detect = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "\n",
    "#调用方法post\n",
    "\n",
    "\n",
    "#准备url传递参数\n",
    "payload = {\n",
    "    \"api_key\":API_Key,\n",
    "    \"api_secret\":API_secret,\n",
    "    \"image_url\":\"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimgsa.baidu.com%2Fexp%2Fw%3D500%2Fsign%3D47ba3b8dd3c451daf6f60ceb86fc52a5%2Fb64543a98226cffc42781c61b7014a90f703ea97.jpg&refer=http%3A%2F%2Fimgsa.baidu.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1649905254&t=492754c86f1dd044463bc527fb7d8092\"\n",
    "}\n",
    "\n",
    "#发起请求\n",
    "r = requests.post(url=face_detect,params=payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "61bf107d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "574a66e2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1647874255,62fd4b0d-9a36-4250-85db-893557252333',\n",
       " 'time_used': 180,\n",
       " 'faces': [{'face_token': '8785dc34669ac8beefc20d5c31f85b8d',\n",
       "   'face_rectangle': {'top': 128, 'left': 77, 'width': 167, 'height': 167}}],\n",
       " 'image_id': 'yedlKpaXEA36/lwGu7spCw==',\n",
       " 'face_num': 1}"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cdd8c630",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "68f6fbe0",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "b3a213f0",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 02\n",
    "#输入我们需要api网站注册的api-key\n",
    "\n",
    "\n",
    "API_Key = \"E5SoP-JF_vrCoNK1gsKRt-10o4kaTm5r\"\n",
    "API_secret = \"TSlEaPXdmJV5w7xkKzuBW_IMRRoPKOXv\"\n",
    "\n",
    "#准备api测试接口的url\n",
    "face_detect = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "\n",
    "#调用方法post\n",
    "\n",
    "\n",
    "#准备url传递参数\n",
    "payload = {\n",
    "    \"api_key\":API_Key,\n",
    "    \"api_secret\":API_secret,\n",
    "    \"image_url\":\"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fnimg.ws.126.net%2F%3Furl%3Dhttp%253A%252F%252Fdingyue.ws.126.net%252F2021%252F0517%252Fe222e910j00qt88w7000od000hs00g5p.jpg%26thumbnail%3D650x2147483647%26quality%3D80%26type%3Djpg&refer=http%3A%2F%2Fnimg.ws.126.net&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1650466964&t=6dbe0c06636c10e934ab9b630d425180\"}\n",
    "\n",
    "#发起请求\n",
    "r = requests.post(url=face_detect,params=payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "c18a21bd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "5b028b4f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1647875010,db2f8da7-f9ec-4931-87ed-8ca8eeb482a1',\n",
       " 'time_used': 228,\n",
       " 'faces': [{'face_token': '185857c089b5f56c06a21be758d86d62',\n",
       "   'face_rectangle': {'top': 157, 'left': 207, 'width': 144, 'height': 144}}],\n",
       " 'image_id': 'Q8fghfFzITZjVRZpX+ePyg==',\n",
       " 'face_num': 1}"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b1e9ffc0",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "79a3f374",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5aac3ed7",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bb01d900",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c79a927f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "64ae7c94",
   "metadata": {},
   "source": [
    "# 人脸分析api"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "6994e21b",
   "metadata": {},
   "outputs": [],
   "source": [
    "#01\n",
    "import requests\n",
    "# 1. url \n",
    "Analyze_base_url = \"https://api-cn.faceplusplus.com/facepp/v3/face/analyze\"\n",
    "\n",
    "# 2. api账户/通行证\n",
    "API_key = 'E5SoP-JF_vrCoNK1gsKRt-10o4kaTm5r'\n",
    "API_sercret = 'TSlEaPXdmJV5w7xkKzuBW_IMRRoPKOXv'\n",
    "\n",
    "# 3 POST\n",
    "\n",
    "# 4. 权限：所有 API Key 都可以调用本 API\n",
    "\n",
    "# 5. payload： 酬载, 必要阅读api文档中的 *必选项* 和 *可选性*，及 *参数说明*\n",
    "payload = {\n",
    "    'api_key':API_key,\n",
    "    'api_secret':API_sercret,\n",
    "    'face_tokens':'8785dc34669ac8beefc20d5c31f85b8d',\n",
    "    'return_attributes':'gender,age,smiling,headpose,facequality,blur,eyestatus,emotion,beauty,mouthstatus,eyegaze,skinstatus',\n",
    "    'beauty_score_min':0,\n",
    "    'beauty_score_max':100\n",
    "    \n",
    "}\n",
    "\n",
    "# 6. requests\n",
    "\n",
    "r_analyze = requests.post(url = Analyze_base_url, params = payload)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "5316e748",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_analyze"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "418f332e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'time_used': 301,\n",
       " 'request_id': '1647874865,82cb6210-8587-4803-b9d9-93304094a186',\n",
       " 'faces': [{'attributes': {'emotion': {'sadness': 0.028,\n",
       "     'neutral': 99.403,\n",
       "     'disgust': 0.002,\n",
       "     'anger': 0.003,\n",
       "     'surprise': 0.038,\n",
       "     'fear': 0.002,\n",
       "     'happiness': 0.525},\n",
       "    'beauty': {'female_score': 90.113, 'male_score': 91.692},\n",
       "    'gender': {'value': 'Male'},\n",
       "    'age': {'value': 23},\n",
       "    'mouthstatus': {'close': 100.0,\n",
       "     'surgical_mask_or_respirator': 0.0,\n",
       "     'open': 0.0,\n",
       "     'other_occlusion': 0.0},\n",
       "    'glass': {'value': 'None'},\n",
       "    'skinstatus': {'dark_circle': 2.668,\n",
       "     'stain': 5.782,\n",
       "     'acne': 3.052,\n",
       "     'health': 40.115},\n",
       "    'headpose': {'yaw_angle': 1.0376397,\n",
       "     'pitch_angle': 7.9734025,\n",
       "     'roll_angle': -4.5684233},\n",
       "    'blur': {'blurness': {'threshold': 50.0, 'value': 0.361},\n",
       "     'motionblur': {'threshold': 50.0, 'value': 0.361},\n",
       "     'gaussianblur': {'threshold': 50.0, 'value': 0.361}},\n",
       "    'smile': {'threshold': 50.0, 'value': 11.298},\n",
       "    'eyestatus': {'left_eye_status': {'normal_glass_eye_open': 0.0,\n",
       "      'no_glass_eye_close': 0.0,\n",
       "      'occlusion': 0.0,\n",
       "      'no_glass_eye_open': 100.0,\n",
       "      'normal_glass_eye_close': 0.0,\n",
       "      'dark_glasses': 0.0},\n",
       "     'right_eye_status': {'normal_glass_eye_open': 0.0,\n",
       "      'no_glass_eye_close': 0.0,\n",
       "      'occlusion': 0.0,\n",
       "      'no_glass_eye_open': 100.0,\n",
       "      'normal_glass_eye_close': 0.0,\n",
       "      'dark_glasses': 0.0}},\n",
       "    'facequality': {'threshold': 70.1, 'value': 92.383},\n",
       "    'eyegaze': {'right_eye_gaze': {'position_x_coordinate': 0.504,\n",
       "      'vector_z_component': 0.953,\n",
       "      'vector_x_component': 0.015,\n",
       "      'vector_y_component': -0.302,\n",
       "      'position_y_coordinate': 0.427},\n",
       "     'left_eye_gaze': {'position_x_coordinate': 0.511,\n",
       "      'vector_z_component': 0.979,\n",
       "      'vector_x_component': 0.131,\n",
       "      'vector_y_component': -0.158,\n",
       "      'position_y_coordinate': 0.426}}},\n",
       "   'face_rectangle': {'width': 167, 'top': 128, 'left': 77, 'height': 167},\n",
       "   'face_token': '8785dc34669ac8beefc20d5c31f85b8d'}]}"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_analyze.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b809f8f2",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f97c6952",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "1a9b8394",
   "metadata": {},
   "outputs": [],
   "source": [
    "#02\n",
    "#01\n",
    "import requests\n",
    "# 1. url \n",
    "Analyze_base_url = \"https://api-cn.faceplusplus.com/facepp/v3/face/analyze\"\n",
    "\n",
    "# 2. api账户/通行证\n",
    "API_key = 'E5SoP-JF_vrCoNK1gsKRt-10o4kaTm5r'\n",
    "API_sercret = 'TSlEaPXdmJV5w7xkKzuBW_IMRRoPKOXv'\n",
    "\n",
    "# 3 POST\n",
    "\n",
    "# 4. 权限：所有 API Key 都可以调用本 API\n",
    "\n",
    "# 5. payload： 酬载, 必要阅读api文档中的 *必选项* 和 *可选性*，及 *参数说明*\n",
    "payload = {\n",
    "    'api_key':API_key,\n",
    "    'api_secret':API_sercret,\n",
    "    'face_tokens':'185857c089b5f56c06a21be758d86d62',\n",
    "    'return_attributes':'gender,age,smiling,headpose,facequality,blur,eyestatus,emotion,beauty,mouthstatus,eyegaze,skinstatus',\n",
    "    'beauty_score_min':0,\n",
    "    'beauty_score_max':100\n",
    "    \n",
    "}\n",
    "\n",
    "# 6. requests\n",
    "\n",
    "r_analyze = requests.post(url = Analyze_base_url, params = payload)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "1030d501",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_analyze"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "b859c314",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'time_used': 157,\n",
       " 'request_id': '1647875136,138527ba-9be9-4068-94f7-c691beea87e4',\n",
       " 'faces': [{'attributes': {'emotion': {'sadness': 0.149,\n",
       "     'neutral': 81.157,\n",
       "     'disgust': 0.276,\n",
       "     'anger': 0.065,\n",
       "     'surprise': 0.031,\n",
       "     'fear': 0.231,\n",
       "     'happiness': 18.092},\n",
       "    'beauty': {'female_score': 80.899, 'male_score': 78.102},\n",
       "    'gender': {'value': 'Male'},\n",
       "    'age': {'value': 31},\n",
       "    'mouthstatus': {'close': 99.886,\n",
       "     'surgical_mask_or_respirator': 0.01,\n",
       "     'open': 0.02,\n",
       "     'other_occlusion': 0.084},\n",
       "    'glass': {'value': 'None'},\n",
       "    'skinstatus': {'dark_circle': 3.877,\n",
       "     'stain': 8.294,\n",
       "     'acne': 2.477,\n",
       "     'health': 39.176},\n",
       "    'headpose': {'yaw_angle': 12.056048,\n",
       "     'pitch_angle': 10.075561,\n",
       "     'roll_angle': -7.6420593},\n",
       "    'blur': {'blurness': {'threshold': 50.0, 'value': 1.718},\n",
       "     'motionblur': {'threshold': 50.0, 'value': 1.718},\n",
       "     'gaussianblur': {'threshold': 50.0, 'value': 1.718}},\n",
       "    'smile': {'threshold': 50.0, 'value': 68.081},\n",
       "    'eyestatus': {'left_eye_status': {'normal_glass_eye_open': 0.026,\n",
       "      'no_glass_eye_close': 0.0,\n",
       "      'occlusion': 0.0,\n",
       "      'no_glass_eye_open': 99.974,\n",
       "      'normal_glass_eye_close': 0.0,\n",
       "      'dark_glasses': 0.0},\n",
       "     'right_eye_status': {'normal_glass_eye_open': 0.009,\n",
       "      'no_glass_eye_close': 0.0,\n",
       "      'occlusion': 0.0,\n",
       "      'no_glass_eye_open': 99.991,\n",
       "      'normal_glass_eye_close': 0.0,\n",
       "      'dark_glasses': 0.0}},\n",
       "    'facequality': {'threshold': 70.1, 'value': 65.423},\n",
       "    'eyegaze': {'right_eye_gaze': {'position_x_coordinate': 0.483,\n",
       "      'vector_z_component': 0.888,\n",
       "      'vector_x_component': 0.091,\n",
       "      'vector_y_component': -0.45,\n",
       "      'position_y_coordinate': 0.386},\n",
       "     'left_eye_gaze': {'position_x_coordinate': 0.534,\n",
       "      'vector_z_component': 0.91,\n",
       "      'vector_x_component': 0.249,\n",
       "      'vector_y_component': -0.332,\n",
       "      'position_y_coordinate': 0.377}}},\n",
       "   'face_rectangle': {'width': 144, 'top': 157, 'left': 207, 'height': 144},\n",
       "   'face_token': '185857c089b5f56c06a21be758d86d62'}]}"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_analyze.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b4d8f1ea",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5dcd4d13",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "772e51f5",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d19eb833",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "99b46e08",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "1c8d263c",
   "metadata": {},
   "source": [
    "# 人脸对比api（两次人脸检测分析的结果token）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "735b8dca",
   "metadata": {},
   "outputs": [],
   "source": [
    "####### 人脸检测获取toekn\n",
    "# 1. url-01\n",
    "base_url = 'https://api-cn.faceplusplus.com/facepp/v3/detect'\n",
    "\n",
    "\n",
    "# 2. api账户/通行证\n",
    "API_Key = \"E5SoP-JF_vrCoNK1gsKRt-10o4kaTm5r\"\n",
    "API_secret = \"TSlEaPXdmJV5w7xkKzuBW_IMRRoPKOXv\"\n",
    "\n",
    "# 3. 请求方法：POST\n",
    "\n",
    "# 4. 准备payload（酬载）\n",
    "payload = {\n",
    "    \"api_key\":API_Key,\n",
    "    \"api_secret\":API_secret,\n",
    "    \"image_url\":\"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimgsa.baidu.com%2Fexp%2Fw%3D500%2Fsign%3D47ba3b8dd3c451daf6f60ceb86fc52a5%2Fb64543a98226cffc42781c61b7014a90f703ea97.jpg&refer=http%3A%2F%2Fimgsa.baidu.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1649905254&t=492754c86f1dd044463bc527fb7d8092\"\n",
    "}\n",
    "\n",
    "# 5. 发起请求\n",
    "r = requests.post(url = base_url, params = payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "5048f264",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'87d8ea27051c66aea029bc9db724f5eb'"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "face_token01 = r.json()[\"faces\"][0]['face_token']\n",
    "face_token01"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c43fd962",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cd40d047",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "e33ff175",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1. url-02\n",
    "base_url = 'https://api-cn.faceplusplus.com/facepp/v3/detect'\n",
    "\n",
    "\n",
    "# 2. api账户/通行证\n",
    "API_Key = \"E5SoP-JF_vrCoNK1gsKRt-10o4kaTm5r\"\n",
    "API_secret = \"TSlEaPXdmJV5w7xkKzuBW_IMRRoPKOXv\"\n",
    "\n",
    "# 3. 请求方法：POST\n",
    "\n",
    "# 4. 准备payload（酬载）\n",
    "payload = {\n",
    "    \"api_key\":API_Key,\n",
    "    \"api_secret\":API_secret,\n",
    "    \"image_url\":\"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fnimg.ws.126.net%2F%3Furl%3Dhttp%253A%252F%252Fdingyue.ws.126.net%252F2021%252F0517%252Fe222e910j00qt88w7000od000hs00g5p.jpg%26thumbnail%3D650x2147483647%26quality%3D80%26type%3Djpg&refer=http%3A%2F%2Fnimg.ws.126.net&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1650466964&t=6dbe0c06636c10e934ab9b630d425180\"}\n",
    "\n",
    "\n",
    "# 5. 发起请求\n",
    "r = requests.post(url = base_url, params = payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "3eb94259",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'a0f8daf2dd0c8c1534908b92437d77e5'"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "face_token02 = r.json()[\"faces\"][0]['face_token']\n",
    "face_token02"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3d750fc8",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "88cf33e1",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a1e7c7eb",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 进行对比"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "2a538088",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1. url\n",
    "compare_url = 'https://api-cn.faceplusplus.com/facepp/v3/compare'\n",
    "\n",
    "\n",
    "# 2. api账户/通行证\n",
    "API_Key = \"E5SoP-JF_vrCoNK1gsKRt-10o4kaTm5r\"\n",
    "API_secret = \"TSlEaPXdmJV5w7xkKzuBW_IMRRoPKOXv\"\n",
    "\n",
    "# 3. 请求方法：POST\n",
    "\n",
    "# 4. 准备payload（酬载）\n",
    "payload = {\n",
    "    'api_key':API_key,\n",
    "    'api_secret':API_sercret,\n",
    "    'face_token1':'87d8ea27051c66aea029bc9db724f5eb',\n",
    "    'face_token2':'a0f8daf2dd0c8c1534908b92437d77e5'\n",
    "}\n",
    "\n",
    "# 5. 发起请求\n",
    "r = requests.post(url = compare_url, params = payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "4cbde1a3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "0a9eaec1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1647875648,679175cb-3762-4fd8-a2e0-78ef86d1faea',\n",
       " 'time_used': 399,\n",
       " 'confidence': 40.554,\n",
       " 'thresholds': {'1e-3': 62.327, '1e-4': 69.101, '1e-5': 73.975}}"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "60adb225",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "50d43246",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "17e601ff",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b1d1eb7f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "395c42b2",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "91a022b4",
   "metadata": {},
   "source": [
    "# 封装人脸检测函数，实现快速调用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "d6850208",
   "metadata": {},
   "outputs": [],
   "source": [
    "API_key = 'jRpCaZ34kqNYJ8Zppdc-yGGum_YkETov'\n",
    "API_sercret = 'Vr0PtRCw-ZFwYXTKVfi6aDNaSqlfunK3'\n",
    "img_url_01 = 'https://tse2-mm.cn.bing.net/th/id/OIP-C.Xz3HbYZeNrdUnGJ7vXNzsQHaKO?pid=ImgDet&rs=1'\n",
    "img_url_02 = 'https://tse2-mm.cn.bing.net/th/id/OIP-C.Xz3HbYZeNrdUnGJ7vXNzsQHaKO?pid=ImgDet&rs=2'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "505f0435",
   "metadata": {},
   "outputs": [],
   "source": [
    "def detect_face(API_key,API_sercret,img_url):\n",
    "    \"\"\"face++ API人脸检测函数\"\"\"\n",
    "    base_url = 'https://api-cn.faceplusplus.com/facepp/v3/detect'\n",
    "    payload = {\n",
    "        'api_key':API_key,\n",
    "        'api_secret':API_sercret,\n",
    "        'image_url':img_url\n",
    "    }\n",
    "    r = requests.post(url = base_url, params = payload)\n",
    "    return r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "93fcc751",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'requests' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-11-f35bd17f1571>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mdetect_face\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mAPI_key\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mAPI_sercret\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mimg_url_01\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32m<ipython-input-10-21867e26a29a>\u001b[0m in \u001b[0;36mdetect_face\u001b[1;34m(API_key, API_sercret, img_url)\u001b[0m\n\u001b[0;32m      7\u001b[0m         \u001b[1;34m'image_url'\u001b[0m\u001b[1;33m:\u001b[0m\u001b[0mimg_url\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      8\u001b[0m     }\n\u001b[1;32m----> 9\u001b[1;33m     \u001b[0mr\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mrequests\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpost\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0murl\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mbase_url\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparams\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpayload\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     10\u001b[0m     \u001b[1;32mreturn\u001b[0m \u001b[0mr\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mjson\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mNameError\u001b[0m: name 'requests' is not defined"
     ]
    }
   ],
   "source": [
    "detect_face(API_key,API_sercret,img_url_01)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "c14adbb4",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'requests' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-12-e4ae64c75bd6>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mdetect_face\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mAPI_key\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mAPI_sercret\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mimg_url_02\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32m<ipython-input-10-21867e26a29a>\u001b[0m in \u001b[0;36mdetect_face\u001b[1;34m(API_key, API_sercret, img_url)\u001b[0m\n\u001b[0;32m      7\u001b[0m         \u001b[1;34m'image_url'\u001b[0m\u001b[1;33m:\u001b[0m\u001b[0mimg_url\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      8\u001b[0m     }\n\u001b[1;32m----> 9\u001b[1;33m     \u001b[0mr\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mrequests\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpost\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0murl\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mbase_url\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparams\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpayload\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     10\u001b[0m     \u001b[1;32mreturn\u001b[0m \u001b[0mr\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mjson\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mNameError\u001b[0m: name 'requests' is not defined"
     ]
    }
   ],
   "source": [
    "detect_face(API_key,API_sercret,img_url_02)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "911cfc61",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7b466aa6",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d47679d7",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8f707813",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9c8acf2b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8f2d26d1",
   "metadata": {},
   "outputs": [],
   "source": [
    "人脸搜索API接口和人脸库API组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "40ed5102",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "43809920",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cf8ddba4",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "968ad25c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f8bc1812",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8a856141",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "87a753f2",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c5731aac",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2790988f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "aae2882f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ee774bb3",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "addac9f6",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c1848039",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
